a = int(input())
    
if a//1000==1 or a//1000==2 or a//1000==3 or a//1000==4 or a//1000==5 or a//1000==6 or a//1000==7 or a//1000==8 or a//1000==9:
        
        
        
        for i in range(2,a):
            if a%i==0:
                a = a // 10
                
                    
        print(a)
        if a%10==a//10%10 and a//10%10==a//100%10 and a//100%10==a//1000:
            print(0)
                    
else:
    print(0)
    
 
